//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "BondArguments.h"
using namespace Cephei::QL::Instruments;
#include <gen/QL/PricingEngineArguments.h>
using namespace Cephei::QL;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Instruments::CBondArguments::CBondArguments (boost::shared_ptr<QuantLib::BondArguments>& childNative, Object^ owner) : CPricingEngineArguments(CBondArguments::typeid)
{
#ifdef HANDLE
	_phBondArguments = NULL;
#endif
	_ppBondArguments = &childNative;
    _ppPricingEngineArguments = new boost::shared_ptr<QuantLib::PricingEngineArguments> (boost::dynamic_pointer_cast<QuantLib::PricingEngineArguments> (*_ppBondArguments));
}
Cephei::QL::Instruments::CBondArguments::CBondArguments (QuantLib::BondArguments& childNative, Object^ owner) : CPricingEngineArguments(CBondArguments::typeid)
{
#ifdef HANDLE
	_phBondArguments = NULL;
#endif
	_ppBondArguments = new boost::shared_ptr<QuantLib::BondArguments> (&childNative);
    _ppPricingEngineArguments = new boost::shared_ptr<QuantLib::PricingEngineArguments> (boost::dynamic_pointer_cast<QuantLib::PricingEngineArguments> (*_ppBondArguments));
    _BondArgumentsOwner = owner;
    _PricingEngineArgumentsOwner = owner;
}

Cephei::QL::Instruments::CBondArguments::CBondArguments (CBondArguments^ copy) : CPricingEngineArguments(CBondArguments::typeid)
{
#ifdef HANDLE
	_phBondArguments = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppBondArguments = new boost::shared_ptr<QuantLib::BondArguments> (copy->GetShared());
        _ppPricingEngineArguments = new boost::shared_ptr<QuantLib::PricingEngineArguments> (boost::dynamic_pointer_cast<QuantLib::PricingEngineArguments> (*_ppBondArguments));
    }
}
Cephei::QL::Instruments::CBondArguments::CBondArguments (System::Type^ t) : CPricingEngineArguments(CBondArguments::typeid)
{
#ifdef HANDLE
	_phBondArguments = NULL;
#endif
	if (!t->IsSubclassOf(CBondArguments::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Instruments::CBondArguments::CBondArguments (QuantLib::Handle<QuantLib::BondArguments>& childNative, Object^ owner)  : CPricingEngineArguments(CBondArguments::typeid)
{
	_phBondArguments = &childNative;
	_ppBondArguments = &static_cast<boost::shared_ptr<QuantLib::BondArguments>>(childNative.currentLink());
    _ppPricingEngineArguments = new boost::shared_ptr<QuantLib::PricingEngineArguments> (boost::dynamic_pointer_cast<QuantLib::PricingEngineArguments> (*_ppBondArguments));
    _BondArgumentsOwner = owner;
}
Cephei::QL::Instruments::CBondArguments::CBondArguments (QuantLib::Handle<QuantLib::BondArguments> childNative)  : CPricingEngineArguments(CBondArguments::typeid)
{
	_phBondArguments = &childNative;
	_ppBondArguments = &static_cast<boost::shared_ptr<QuantLib::BondArguments>>(childNative.currentLink());
    _ppPricingEngineArguments = new boost::shared_ptr<QuantLib::PricingEngineArguments> (boost::dynamic_pointer_cast<QuantLib::PricingEngineArguments> (*_ppBondArguments));
}
#endif
#ifdef STRUCT
Cephei::QL::Instruments::CBondArguments::CBondArguments (QuantLib::BondArguments childNative)  : CPricingEngineArguments(CBondArguments::typeid)
{
#ifdef HANDLE
	_phBondArguments = NULL;
#endif
	_ppBondArguments = new boost::shared_ptr<QuantLib::BondArguments> (new QuantLib::BondArguments (childNative));
    _ppPricingEngineArguments = new boost::shared_ptr<QuantLib::PricingEngineArguments> (boost::dynamic_pointer_cast<QuantLib::PricingEngineArguments> (*_ppBondArguments));
}
#endif

Cephei::QL::Instruments::CBondArguments::~CBondArguments ()
{
    if (_ppBondArguments != NULL)
    {
	    delete _ppBondArguments;
        _ppBondArguments = NULL;
    }
}
Cephei::QL::Instruments::CBondArguments::!CBondArguments ()
{
    if (_ppBondArguments != NULL)
    {
	    delete _ppBondArguments;
    }
}
QuantLib::BondArguments& Cephei::QL::Instruments::CBondArguments::GetReference ()
{
    if (_ppBondArguments == NULL) throw gcnew NativeNullException ();
	return **_ppBondArguments;
}
boost::shared_ptr<QuantLib::BondArguments>& Cephei::QL::Instruments::CBondArguments::GetShared ()
{
    if (_ppBondArguments == NULL) throw gcnew NativeNullException ();
	return *_ppBondArguments;
}
QuantLib::BondArguments* Cephei::QL::Instruments::CBondArguments::GetPointer ()
{
    if (_ppBondArguments == NULL) throw gcnew NativeNullException ();
	return &**_ppBondArguments;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::BondArguments>& Cephei::QL::Instruments::CBondArguments::GetHandle ()
{
	if (_phBondArguments == NULL)
	{
		_phBondArguments = new Handle<QuantLib::BondArguments> (*_ppBondArguments);
	}
	return *_phBondArguments;
}
#endif
bool Cephei::QL::Instruments::CBondArguments::HasNative () 
{
	return (_ppBondArguments != NULL);
}

Cephei::QL::Instruments::IBondArguments^ Cephei::QL::Instruments::CBondArguments::Validate::get ()
{
    try
    {
    	(*_ppBondArguments)->validate ( );
    	return this;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

